// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
// import vuex, { Store } from 'vuex'
import Vuex from 'vuex'
import 'element-ui/lib/theme-chalk/index.css';
import './assets/css/style.css'
import './assets/iconfont/iconfont.css'
import fileType from './assets/js/fileType.js'
import preventReClick from './assets/js/preventReClick.js'
import animated from 'animate.css' // npm install animate.css --save安装，在引入
// import 'jquery'
// import { quillEditor } from 'vue-quill-editor'
// import 'quill/dist/quill.core.css'
// import 'quill/dist/quill.snow.css'
// import 'quill/dist/quill.bubble.css'
// 富文本编辑器
// import VueQuillEditor from 'vue-quill-editor'
// import 'quill/dist/quill.core.css'
// import 'quill/dist/quill.snow.css'
// import 'quill/dist/quill.bubble.css'
// // import '@/styles/index.scss' // global css
// Vue.use(VueQuillEditor)
import axios from 'axios'
Vue.prototype.fileType = fileType
Vue.prototype.$http = axios
axios.defaults.baseURL = 'http://127.0.0.1:3000/api/'
Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.use(Vuex);
Vue.use(preventReClick);
Vue.use(animated)

// 每次刚进入 网站，肯定会 调用 main.js 在刚调用的时候，先从本地存储中，把 用户的数据读出来，放到 store 中
const user = JSON.parse(localStorage.getItem('user') || '[]');
const show = JSON.parse(localStorage.getItem('show') || '[]');
const verify = JSON.parse(localStorage.getItem('verify') || '[]');
//创建一个vuex状态管理对象
var store = new Vuex.Store({
  state: { // this.$store.state.***
    user:{
      "user_id":"",
      "account":"",
      "password":"",
      "nickname":"",
    },
    isShow:false,
    isVerify:true,
    showRed:false,
  },
  mutations: { // this.$store.commit('方法的名称', '按需传递唯一的参数')
    updateUser(state, user) {
      state.user = user;
      // 当 更新 user_name 之后，把 user_name 数组，存储到 本地的 localStorage 中
      localStorage.setItem('user', JSON.stringify(state.user))
      // console.log("这是user");
      // console.log(state.user);
    },
    updateShow(state,isShow){
      state.isShow = isShow;
      localStorage.setItem('show', JSON.stringify(state.isShow))
    },
    updateVerify(state,isVerify){
      state.isVerify = isVerify;
      localStorage.setItem('verify', JSON.stringify(state.isVerify))
    },
    updateShowRed(state,showRed){
      state.showRed = showRed;
      // localStorage.setItem('verify', JSON.stringify(state.isVerify))
    }
  },
  getters: { // this.$store.getters.***
    // 相当于 计算属性，也相当于 filters
    getUser(state) {
      let User;
      // console.log(state.user.user_id == "");
      if (state.user.user_id == "" || state.user.user_id == null){
      // if (state.user.user_id == undefined){
        User = JSON.parse(localStorage.getItem('user'))
      }else{
        User = state.user
        return User;
      }
      // console.log("-----------user");
      // console.log(User);
      // console.log("------------user");
      return User;
    },
    getShow(state) {
      let isShow;
      if (state.user.user_id == false || state.user.user_id == null){
        isShow = JSON.parse(localStorage.getItem('show'));
      }else{
        isShow = state.isShow
        return isShow;
      }
      return isShow;
    },
    getVerify(state) {
      let isVerify;
      if (state.user.user_id == false || state.user.user_id == null){
        isVerify = JSON.parse(localStorage.getItem('verify'));
      }else{
        isVerify = state.isVerify
        return isVerify;
      }
      return isVerify;
    },
    getShowRed(state){
      return showRed;
    }
  }
})
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  render: h => h(App),
  store,
})
